<template>
  <div class="middle">
    <div class="carouselBox">
      <el-carousel
        height="500px"
        :autoplay="false"
        :motion-blur="true"
        loop
        ref="carouselRef"
      >
        <el-carousel-item v-for="(item, index) in list" :key="index">
          <div class="imgBox">
            <div class="leftBox">
              <img class="carouselImg" :src="item.image" alt="" />
            </div>
            <div class="detail">
              <div class="name">{{ $t("common.highQuality") }}</div>
              <div class="desc" v-html="locale === 'zh-cn' ? aboutUs : enAboutUs"></div>
              <el-button
                type="primary"
                class="btn"
                @click="jumpTo('/productDetail?id=' + item.id)"
                >{{ $t("common.look") }}</el-button
              >
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>
<script setup>
import { reactive, ref, onMounted } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
const I18n = useI18n();
const { locale } = useI18n();

const router = useRouter();
// 跳转页面
const jumpTo = (path) => {
  router.push(path);
};

const imgRef = ref();

const list = ref([]);
const getList = async () => {
  try {
    const res = await axios.get(`${apiUrl}/groom/list/1?page=1&limit=4`, {
      headers: {
        "Authori-zation": `Bearer ${getToken()}`,
      },
    });

    if (res.data.status === 200) {
      list.value = res.data.data.list;
    }
  } catch (e) {}
};

const aboutUs = ref("");
const getAboutUs = async () => {
  try {
    const res = await axios.get(`${apiUrl}/pc/get_news_detail/11`, {
      headers: {
        "Authori-zation": `Bearer ${getToken()}`,
      },
    });

    if (res.data.status === 200) {
      aboutUs.value = res.data.data.content.replace(/^<p>|<\/p>$/g, "");
    }
  } catch (e) {}
};

const enAboutUs = ref("");
const getEnAboutUs = async () => {
  try {
    const res = await axios.get(`${apiUrl}/pc/get_news_detail/12`, {
      headers: {
        "Authori-zation": `Bearer ${getToken()}`,
      },
    });

    if (res.data.status === 200) {
      enAboutUs.value = res.data.data.content.replace(/^<p>|<\/p>$/g, "");
    }
  } catch (e) {}
};

onMounted(() => {
  getList();
  getAboutUs();
  getEnAboutUs();
});
</script>

<style scoped lang="scss">
.middle {
  margin-top: 40px;
  background-color: #fff;
  display: flex;
  box-shadow: 0 0 7px 2px #e1dede5e;

  .carouselBox {
    width: 1220px;
  }

  .carouselImg {
    width: 100%;
    height: 100%;
  }

  .detail {
    padding: 70px 42px;
    width: 314px;
    box-sizing: border-box;

    .name {
      font-size: 25px;
      margin-bottom: 10px;
      margin-top: 60px;
    }

    .desc {
      color: #666;
      width: 100%;
      line-height: 22px;
      margin-bottom: 30px;
      max-height: 150px;
      overflow: hidden;
    }

    .btn {
      width: 104px;
      height: 31px;
      line-height: 31px;
    }
  }
}

.imgBox {
  display: flex;
  .leftBox {
    width: 906px;
    height: 500px;
    overflow: hidden;
  }
}
</style>
